<%@page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="html" tagdir="/WEB-INF/tags" %>
<!DOCTYPE html>
<html>
<html:header title="商品模板">

    <link rel="stylesheet" href="${baseUrl}css/public.css" media="all">

    <style type="text/css">
        a{
            color: #01AAED;
            text-decoration: none;
            font-size: 12px;
        }
        a:hover {
            color: #FF5722;
        }
    </style>

    <script>

        jQuery(function () {
            fixTableOperatorButton();
        });

        layui.use(['form', 'table'], function () {
            let $ = layui.jquery,
                form = layui.form,
                table = layui.table,
                util = layui.util;

            renderTable();



            form.on('checkbox(noShowDisable)', function (data) {
                let json = {};
                json.searchContent = $("[name='searchContent']").val();
                data.elem.checked ? json.status = 1 : json.status = "";
                table.reload('table',{where: json,page: {curr: 1}});
            });

            form.on('submit(search)', function (data) {
                let json = data.field;
                isTrue(data.field.noShowDisable) ? json.status = 1 : json.status = "";
                table.reload('table',{where: json,page: {curr: 1}});
                return false;
            });


            table.on('tool(table)', function (obj) {
                let data = obj.data;
                switch(obj.event){
                    case 'detail':
                        openTab("模板<"+data.name+">详情","${baseUrl}marketGoods/goodsTemplateDetail.action?id="+data.id);
                        break;
                    case 'delete':
                        del(data);
                        break;
                    case 'edit':
                        openTab("模板<"+data.name+">编辑","${baseUrl}marketGoods/goodsTemplateEdit.action?id="+data.id);
                        break;
                };
            });

            table.on('toolbar(table)', function (obj) {
                if (obj.event === 'add') {
                    openTab("新增模板","${baseUrl}marketGoods/goodsTemplateNew.action");
                }
            });

        });

        function renderTable() {
            $("form")[0].reset();
            layui.table.render({
                id:'table',
                elem: '#table',
                toolbar: '#tableToolBar',
                defaultToolbar:[],
                url: "${baseUrl}marketGoods/goodsTemplate/getList.action",
                where : {
                    status :1,
                    time:(new Date()).valueOf()
                },
                cols: [[
                    {width:70,title:"序号",totalRowText: '合计',templet:function (d) {
                            return genTableIndex(d.status == 2, "停用", d);
                        }},
                    {field: 'id', width: 10, title: 'ID',hide:true},
                    {field: 'no', width: 130, title: '模板编号',style:"font-size:12px;"},
                    {field: 'name', width: 150, title: '模板名称',style:"font-size:12px;"},
                    {minWidth: 150, title: '模板商品',style:"font-size:12px;",templet: function(d){
                            return genGoodsAndPacket(d.goodsTemplateGoodsVoList);
                    }},
                    {field: 'remark', width: 120, title: '备注',style:"font-size:12px;"},
                    {title: '操作', minWidth: 80, fixed:'right', templet: '#operBar'},
                ]],
                limit: 10,
                page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                    layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                    //,curr: 5 //设定初始在第 5 页
                    ,groups: 5 //只显示 5 个连续页码
                    ,first: false //不显示首页
                    ,last: false //不显示尾页
                },
                done: function(res, curr, count){
                    setTableLineCss("table",res.data, "status", 2, "font-gray-c2c2c2");
                }
            });

        }

        function del(data) {
            layer.confirm('删除模板《'+data.name+'》?', {icon: 3, title:'删除模板'}, function(index){
                tipLoad("删除中..");
                post("${baseUrl}marketGoods/goodsTemplate/delete.action",{id:data.id}, function (resp) {
                    closeLoading();
                    if (resp.code == 1){
                        closeAll();
                        tip("删除成功");
                        renderTable();
                    } else {
                        tip(resp.msg);
                    }
                });
            });
        }
    </script>

</html:header>
<body>

<div class="layuimini-container">
    <div class="layuimini-main">
        <blockquote class="layui-elem-quote" >通过商品模板可以在开业务单据时快速新增一组商品，适用于销售业务。</blockquote>

        <form class="layui-form layui-form-pane" action="" style="margin-top: 15px;">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <input type="checkbox" name="noShowDisable" title="不显示停用模板" lay-skin="primary" value="true" checked lay-filter="noShowDisable">
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">其他信息</label>
                    <div class="layui-input-inline" style="min-width: 200px;">
                        <input type="text" name="searchContent" placeholder="编号、名称、商品名称、备注" style="font-size: 12px;" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <a class="layui-btn" lay-submit="" lay-filter="search"><i class="layui-icon layui-icon-search"></i></a>
                </div>
            </div>
        </form>
        <hr/>

        <table class="layui-hide" id="table" lay-filter="table" lay-size="sm"></table>

        <script type="text/html" id="tableToolBar">
            <div class="layui-inline">
                <a class="layui-btn" lay-event="add">新增</a>
            </div>
        </script>

        <script type="text/html" id="operBar">
            <a class="layui-btn layui-btn-xs layui-btn-normal table-operator" lay-event="detail">详情</a>
            <a class="layui-btn layui-btn-xs table-operator" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger table-operator" lay-event="delete">删除</a>
        </script>
    </div>
</div>
</body>
<html:loading/>
</html>